package com.example.farmeri.ui.data_collect;

import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;

import androidx.appcompat.app.AlertDialog;

import com.example.farmeri.R;
import com.example.farmeri.ui.base.BaseActivity;

import java.util.Timer;
import java.util.TimerTask;

import butterknife.BindView;
import butterknife.ButterKnife;

public class DataCollectActivity extends BaseActivity {

    @BindView(R.id.data_collect_loading)
    ViewGroup loading;

    AlertDialog dialog ;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_data_collect);
        ButterKnife.bind(this);
        initToolBar(R.id.data_collect_toolbar,"数据采集",true,true);
    }

    public void collect(View view) {
        if (dialog == null){
            initDialog();
        }
        loading.setVisibility(View.VISIBLE);
        new Timer().schedule(new TimerTask() {
            @Override
            public void run() {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        loading.setVisibility(View.GONE);
                        dialog.show();
                    }
                });
            }
        }, 1000);
    }

    private void initDialog() {
        dialog = new AlertDialog.Builder(this).create();
        dialog.setTitle("消息");
        dialog.setMessage("添加成功");
        dialog.setButton(DialogInterface.BUTTON_POSITIVE, "确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });
    }
}
